<!--
 * @Description: 主页tab
 * @Author: charles
 * @Date: 2021-12-14 20:42:55
 * @LastEditors: LiKun
 * @LastEditTime: 2022-01-05 15:54:25
-->
<template>
  <div class="home">
    <van-nav-bar title="首页" />
    <!-- 标签页区域 -->
    <van-tabs @click="tabClickHandler" v-model="active">
      <van-tab title="全部"></van-tab>
      <van-tab title="安装"></van-tab>
      <van-tab title="维修"></van-tab>
      <van-tab title="拆机"></van-tab>
    </van-tabs>
    <div class="orderList">
      <div
        class="box"
        v-for="(item, index) in orderList"
        :key="index"
        @click="$router.push({ path: '/orderDetails', query: item })"
      >
        <div class="left">
          <img width="70px" src="../../assets/order.png" alt="" />
        </div>
        <div class="right">
          <div>
            <strong>工单状态：</strong>
            <van-tag size="medium" type="danger">{{ item.status }}</van-tag>
          </div>
          <div><strong>工单类型：</strong>{{ item.type }}</div>
          <div><strong>申报时间：</strong>{{ item.create_time | datefmt }}</div>
        </div>
      </div>
    </div>
  </div>
</template>
<script>
// 请求方法的导入
import { get } from "@/utils/request.js";
export default {
  data() {
    return {
      active: 1,
      params: {
        page: 1,
        pageSize: 100,
        status: "待接单",
      },
      orderList: [],
    };
  },
  methods: {
    // 查询工单
    getAllWorkerOrdersByType() {
      switch (this.active) {
        case 0:
          break;
        case 1:
          this.params.type = "安装";
          break;
        case 2:
          this.params.type = "维修";
          break;
        case 3:
          this.params.type = "拆机";
          break;
      }
      get("/workorder/pageQuery", this.params).then((res) => {
        this.orderList = res.data.list;
      });
    },
    // tab标签点击处理函数
    tabClickHandler(name, title) {
      if (title == "全部") {
        this.params = {
          page: 1,
          pageSize: 100,
          status: "待接单",
        };
      } else {
        this.params.type = title;
      }
      // 重载数据
      this.getAllWorkerOrdersByType();
    },
  },
  created() {
    this.getAllWorkerOrdersByType();
  },
};
</script>
<style scoped>
.box {
  height: 95px;
  margin: 10px 20px;
  padding: 10px;
  border: 1px solid rgb(156, 154, 154);
  border-radius: 10px;
  display: flex;
  cursor: pointer;
}
.left {
  width: 85px;
}
.right {
  width: calc(100% - 85px);
}
.right > div {
  height: 24px;
  line-height: 24px;
  font-size: 16px;
}
</style>